﻿using Hotel_Project.Bean;
using Hotel_Project.BIZ;
using Hotel_Project.Tools.MySqlBrushData_Helps;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Hotel_Project.HotelForm
{
    public partial class UserManage : Form
    {
        private static Form userManage = null;
        public UserManage()
        {
            InitializeComponent();
        }
        //调用的窗口
        private static UserManagement forms = null;
        public static Form getFrom(UserManagement form1)
        {
            if (userManage==null)
            {
                userManage = new UserManage();
            }
            forms = form1;
            return userManage;
        }
        private void UserManage_Load(object sender, EventArgs e)
        {
            forms.Fulsh(dataGridView1);
            forms.Fulsh(forms.adminDataView);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            UserManageAction us = new UserManageAction();
            string text = comboBox1.Text.Trim().ToString();
            string sql = $"insert into admin(a_id,a_password,a_admin,a_name,a_run) value({textBox1.Text.Trim()},{textBox2.Text.Trim()},'{text}',{textBox3.Text.Trim()},{1});";
            us.add(sql);
            forms.Fulsh(dataGridView1);
            forms.Fulsh(forms.adminDataView);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            UserManageAction us = new UserManageAction();
            string s = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            string sql = $"DELETE FROM admin WHERE a_id='{s}';";
            us.remove(sql);
            forms.Fulsh(dataGridView1);
            forms.Fulsh(forms.adminDataView);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            UserManageAction us = new UserManageAction();
            string s = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            string paw= dataGridView1.CurrentRow.Cells[1].Value.ToString();
            string zi = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            string name= dataGridView1.CurrentRow.Cells[3].Value.ToString();
            string sql = $"UPDATE admin SET a_password='{paw}',a_admin='{zi}',a_name='{name}' WHERE a_id='{s}';";
            us.select(sql);
            forms.Fulsh(dataGridView1);
            forms.Fulsh(forms.adminDataView);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
